import time
from flask import render_template
from flask import request
from application.views.api.callback import callback
from application.views.backe_data_reload import back
from application.views.course import course_blue
from application.views.tcourse import tcourse_blue
from application.views.index import index_blue
from application.views.user import user_blue
import requests
from flask_socketio import emit,join_room
from application.views.news import news_blue
from application.views.ws import socket
from create_app import CreateFlask
from flask_login import login_required



flask_obj = CreateFlask()
app = flask_obj.app

app.register_blueprint(user_blue, url_prefix='/user')
app.register_blueprint(back, url_prefix='/back')
app.register_blueprint(callback, url_prefix='/callback')
app.register_blueprint(course_blue, url_prefix='/course')
app.register_blueprint(tcourse_blue,url_prefix='/tcourse')
app.register_blueprint(news_blue,url_prefix='/news')
app.register_blueprint(index_blue, url_prefix='/index')

@app.route('/',methods=['get'])
def index():
#     data = request.json
#     # 机器人id
#     url = "https://oapi.dingtalk.com/robot/send?access_token=8ca7b7831d56811e6be0ae87d371e48dc0977c265ed6096db97199fd9b6d789c"
#     ret = requests.post(url, json={
#         "msgtype": "markdown",
#         "markdown": {
#             "title": "监控",
#             "text": f"""#### 健康系统 \n
#
# > cpu {data['cpu_info']}\n
# > 中分头背带裤,我是细狗你记住 {data['total_memory']}G\n
# > 社会摇中万人迷，唯有男神牌牌杰 {int(data['used_memory'])}\n
# @17611406668"""
#         },
#         "at": {
#             "atMobiles": [
#                 "17611406668"
#             ],
#             "atUserIds": [
#                 "vqt_2ayf8q6bb"
#             ],
#             "isAtAll": False
#         }
#     })
#     print(ret.json())
#     return 'asdf'
    return render_template('ws_index.html',async_mode='123')

@app.route('/player', methods=['GET'])
def Film_Play():
    return render_template('player.html', movie={'file': 'vip.mp4', 'title': '???'})


if __name__ == '__main__':
    print(app.url_map)
    # app.run(host='0.0.0.0', port=8000, threaded=True)
    socket.run(app, host='0.0.0.0', port=8000, debug=True)

# flask-socketio==5.3.3
# eventlet==0.33.3